from PyQt5 import QtWidgets
from PyQt5 import QtCore
import sys

class QCheckBoxTest(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(QCheckBoxTest, self).__init__(parent)

        self.setWindowTitle("QCheckBox test")

        self.check_box_1 = QtWidgets.QCheckBox("&Checkbox1")
        self.check_box_1.setChecked(True)
        self.check_box_1.stateChanged.connect(lambda: self.check_box_state(self.check_box_1))


        self.check_box_2 = QtWidgets.QCheckBox("CheckBox2")
        self.check_box_2.toggled.connect(lambda: self.check_box_state(self.check_box_2))

    
        self.check_box_3 = QtWidgets.QCheckBox("CheckBox3")
        self.check_box_3.setTristate(True)
        self.check_box_3.setCheckState(QtCore.Qt.PartiallyChecked)
        self.check_box_3.stateChanged.connect(lambda: self.check_box_state(self.check_box_3))

        _h_box_layout = QtWidgets.QHBoxLayout()
        _h_box_layout.addWidget(self.check_box_1)
        _h_box_layout.addWidget(self.check_box_2)
        _h_box_layout.addWidget(self.check_box_3)

        _group_box = QtWidgets.QGroupBox("Check Boxs")
        _group_box.setFlat(True)
        _group_box.setLayout(_h_box_layout)

        _main_layout = QtWidgets.QVBoxLayout()
        _main_layout.addWidget(_group_box)
        self.setLayout(_main_layout)

    def check_box_state(self, check_box):
        print(check_box.text())
        print(check_box.isChecked())
        print(check_box.checkState())

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    QtWidgets.QApplication.setStyle("Fusion")

    win = QCheckBoxTest()
    win.show()

    sys.exit(app.exec_())